﻿using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Enterprise.Migrations
{
    public partial class addsimpledict : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.RenameIndex(
                name: "IX_MDT_ORDER_PATIENT_ID_VISIT_ID_MDT_ID_ORDER_NO_ORDER_SUB_NO",
                table: "MDT_ORDER",
                newName: "IXU_MDT_ORDER");

            migrationBuilder.AlterColumn<string>(
                name: "VISIT_ID",
                table: "MDT_ORDER",
                type: "VARCHAR(20)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "VARCHAR(20)",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "PATIENT_ID",
                table: "MDT_ORDER",
                type: "VARCHAR(20)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "VARCHAR(20)",
                oldNullable: true);

            migrationBuilder.AddColumn<int>(
                name: "SIMPLE_ITEM_CODE",
                table: "MDT_MASTER",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<string>(
                name: "SIMPLE_TYPE_CODE",
                table: "MDT_MASTER",
                type: "VARCHAR(20)",
                nullable: false,
                defaultValue: "");

            migrationBuilder.CreateTable(
                name: "SIMPLE_DICT",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    TYPE_CODE = table.Column<string>(type: "VARCHAR(20)", nullable: false),
                    TYPE_NAME = table.Column<string>(type: "VARCHAR(20)", nullable: false),
                    ITEM_CODE = table.Column<int>(nullable: false),
                    ITEM_NAME = table.Column<string>(type: "VARCHAR(20)", nullable: false),
                    INPUT_CODE = table.Column<string>(type: "VARCHAR(20)", nullable: false),
                    INPUT_CODE_WB = table.Column<string>(type: "VARCHAR(20)", nullable: true),
                    SORT = table.Column<short>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SIMPLE_DICT", x => x.Id);
                });
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SIMPLE_DICT");

            migrationBuilder.DropColumn(
                name: "SIMPLE_ITEM_CODE",
                table: "MDT_MASTER");

            migrationBuilder.DropColumn(
                name: "SIMPLE_TYPE_CODE",
                table: "MDT_MASTER");

            migrationBuilder.RenameIndex(
                name: "IXU_MDT_ORDER",
                table: "MDT_ORDER",
                newName: "IX_MDT_ORDER_PATIENT_ID_VISIT_ID_MDT_ID_ORDER_NO_ORDER_SUB_NO");

            migrationBuilder.AlterColumn<string>(
                name: "VISIT_ID",
                table: "MDT_ORDER",
                type: "VARCHAR(20)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "VARCHAR(20)");

            migrationBuilder.AlterColumn<string>(
                name: "PATIENT_ID",
                table: "MDT_ORDER",
                type: "VARCHAR(20)",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "VARCHAR(20)");
        }
    }
}
